package com.xcity.game.activity.newplayer;

import naga.x.game.template.Template;
import naga.x.game.template.TemplateException;
import naga.x.game.template.annotation.Binding;
import naga.x.game.template.annotation.Excel;

/**
 * 创角活动
 * @author shipeng.zhu
 *
 */
@Excel(value = "newPlayer.xlsx", sheetName = "创角活动")
public class NewPlayerTaskTemplate extends Template {

	/** 活动目标类型 */
	protected byte type;

	/** 第X天开放 */
	protected byte startDay;

	/** 标签分类 */
	protected byte tab;

	/** 是否弃用 */
	protected byte ban;

	/** 奖励钱 */
	protected int money;

	/** 奖励钻石 */
	protected int stone;

	/** 奖励物品ID1 */
	protected int[] itemIds;

	/** 奖励物品数量1 */
	protected int[] itemCounts;

	/** 参数1 */
	protected int[] param;

	public byte getType() {
		return type;
	}

	public void setType(byte type) {
		this.type = type;
	}

	public byte getStartDay() {
		return startDay;
	}

	public void setStartDay(byte startDay) {
		this.startDay = startDay;
	}

	public byte getTab() {
		return tab;
	}

	public void setTab(byte tab) {
		this.tab = tab;
	}

	public byte getBan() {
		return ban;
	}

	public void setBan(byte ban) {
		this.ban = ban;
	}

	public int getMoney() {
		return money;
	}

	public void setMoney(int money) {
		this.money = money;
	}

	public int getStone() {
		return stone;
	}

	public void setStone(int stone) {
		this.stone = stone;
	}

	public int[] getItemIds() {
		return itemIds;
	}

	public void setItemIds(int[] itemIds) {
		this.itemIds = itemIds;
	}

	public int[] getItemCounts() {
		return itemCounts;
	}

	public void setItemCounts(int[] itemCounts) {
		this.itemCounts = itemCounts;
	}

	public int[] getParam() {
		return param;
	}

	public void setParam(int[] param) {
		this.param = param;
	}


	@Override
	public void validate() throws TemplateException {
		if(itemIds == null){
			itemIds = new int[]{};
		}
		if(itemCounts == null){
			itemCounts = new int[]{};
		}
		if(itemIds.length > itemCounts.length){
			int[] newItemCounts = new int[itemIds.length];
			for(int i = 0; i < itemCounts.length; i++){
				newItemCounts[i] = itemCounts[i]; 
			}
			for(int i = itemCounts.length; i < itemIds.length; i++){
				newItemCounts[i] = 1;
			}
			itemCounts = newItemCounts;
		}
		if(itemIds.length < itemCounts.length){
			int[] newItemCounts = new int[itemIds.length];
			for(int i = 0; i < itemIds.length; i++){
				newItemCounts[i] = itemCounts[i];
			}
			itemCounts = newItemCounts;
		}
		if(itemIds.length != itemCounts.length){
			throw new TemplateException("newplayer.xlsx奖励数量配置错误->id=" + id);
		}
		for(int i = 0; i < itemIds.length; i++){
			if(itemIds[i] > 0){
				if(itemCounts[i] <= 0){
					throw new TemplateException("newplayer.xlsx奖励数量配置错误->id=" + id);
				}
			}
		}
		int[] newparam = new int[]{0, 0, 0};
		for(int i = 0; i < param.length; i++){
			newparam[i] = param[i];
		}
		this.param = newparam;
		if(param[0] < 0 || param[0] > NewPlayerTracer.PARAM0_MAX){
			throw new TemplateException("newplayer.xlsx参数1配置错误->id=" + id);
		}
		if(param[1] < 0 || param[1] > NewPlayerTracer.PARAM1_MAX){
			throw new TemplateException("newplayer.xlsx参数2配置错误->id=" + id);
		}
		if(param[2] < 0 || param[2] > NewPlayerTracer.PARAM2_MAX){
			throw new TemplateException("newplayer.xlsx参数3配置错误->id=" + id);
		}
		if(tab == 0){
			throw new TemplateException("newplayer.xlsx标签类型错误->id=" + id);
		}
		if(type == 0){
			throw new TemplateException("newplayer.xlsx类型错误->id" + id);
		}
	}
}
